package org.hishenframework.core.web.upload;

import java.io.File;
import java.io.IOException;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.commons.io.FileUtils;

/**
 * 临时文件清除类
 * sessionDestroyed()	session销毁后删除临时目录方法(session监听)
 * @author zhangdi
 *
 */
public class HishenTempFileCleanListner implements HttpSessionListener {

	@Override
	public void sessionCreated(HttpSessionEvent e) {
		e.getSession().setMaxInactiveInterval(15);
	}

	/**
	 * session销毁
	 * 删除用户临时文件夹
	 */
	@Override
	public void sessionDestroyed(HttpSessionEvent e) {
		String path = e.getSession().getServletContext().getRealPath("") + HishenUploader.UPLOAD_PATH + "/" + e.getSession().getId();
		try {
			FileUtils.deleteDirectory(new File(path));
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	}

}
